package com.ins1st.plus.core.run;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ins1st.plus.api.system.config.entity.SysConstants;
import com.ins1st.plus.api.system.config.service.SysConstantsApi;
import com.ins1st.plus.constants.ContextConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: ins1st-plus
 * @description: 启动配置类
 * @author: coderSun
 * @create: 2019-09-07 22:52
 **/
@Order(value = 1)
@Component
public class ContextContantsRun implements ApplicationRunner {

    private static final Logger log = LoggerFactory.getLogger(ContextContantsRun.class);

    @Reference
    SysConstantsApi sysConstantsApi;

    private static ContextConstants contextConstants = new ContextConstants();

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<SysConstants> sysConstantsList = sysConstantsApi.list();
        for (SysConstants constants : sysConstantsList) {
            contextConstants.put(constants.getConstantsKey(), constants.getConstantsValue());
        }
        log.info("成功初始化{}条配置", sysConstantsList.size());
    }
}
